<?php

namespace app\api\controller;
use think\Db;
class My extends \app\api\controller\Base {

    public function index()
    {
        /**
         * 首页——获取我的基础信息和未读消息
         * sheng，shi
         */
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $data = Db::table('up_u_user')->where('user_id',$user_id)->field('user_image,user_username')->find();
        $td = date('Y-m-d');
        $auth = Db::table('up_user_auth')
            ->where('uauth_user_id',$user_id)
            ->where('uauth_start','<=',$td)
            ->where('uauth_end','>=',$td)
            ->order('uauth_type DESC')
            ->value('uauth_type');
        $data['auth'] = '普通';
        if($auth){
            if($auth == 2){$data['auth'] = '铜牌';}
            if($auth == 3){$data['auth'] = '银牌';}
            if($auth == 4){$data['auth'] = '金牌';}
        }
        //=========================精准消息未读的=============================
        if(!isset($sheng) || $sheng==''){$sheng=0;}
        if(!isset($shi) || $shi==''){$shi=0;}
        $today = date('Y-m-d H:i:s');
        $start = date("Y-m-d H:i:s",(strtotime("{$today}")-3600*24*1));
        $num1 = Db::table('up_article')->alias('a')
            ->join('up_article_son as','a.a_id=as.as_article_id','LEFT')
            ->join('up_u_user uu','a.a_user_id=uu.user_id','LEFT')
            ->where(function ($query) use ($shi,$start,$user_id) {
                $query->where('a_auth_type',2)->where('a_auth_city',$shi)->where('a_createtime','>=',$start)->where('as_clear_users','notlike',"%,$user_id,%")->where('as_read_users','notlike',"%,$user_id,%");
            })
            ->whereOr(function ($query) use ($sheng,$start,$user_id) {
                $query->where('a_auth_type',3)->where('a_auth_city',$sheng)->where('a_createtime','>=',$start)->where('as_clear_users','notlike',"%,$user_id,%")->where('as_read_users','notlike',"%,$user_id,%");
            })
            ->whereOr(function ($query) use ($start,$user_id){
                $query->where('a_auth_type',4)->where('a_createtime','>=',$start)->where('as_clear_users','notlike',"%,$user_id,%")->where('as_read_users','notlike',"%,$user_id,%");
            })
            ->field('a_id')
            ->count();
        //=========================系统消息未读的=============================
        $time2 = Db::table('up_u_user')->where('user_id',$user_id)->value('user_time');
        $num2 = Db::table('up_notice')
            ->where(function ($query) use ($user_id,$time2) {
                $query->where('n_user_id',$user_id)->where('n_status',1)->where('n_createtime','>',$time2);
            })
            ->whereOr(function ($query) use ($user_id,$time2) {
                $query->where('n_send_type',1)->where('n_createtime','>',$time2)->where('n_clear_users','notlike',"%,$user_id,%")->where('n_read_users','notlike',"%,$user_id,%");
            })
            ->field('n_id')
            ->count();
        $num = $num1+$num2;
        if($num > 99){
            $num = '99+';
        }
        $data['num'] = $num;
        return json_encode(['status'=>200,'msg'=>$data]);
    }
    /**
     * 我的消息——精准消息
     * sheng，shi,page
     */
    public  function MyPushNotice()
    {
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $today = date('Y-m-d H:i:s');
        $start = date("Y-m-d H:i:s",(strtotime("{$today}")-3600*24*1));
        if(!isset($sheng) || $sheng==''){$sheng=0;}
        if(!isset($shi) || $shi==''){$shi=0;}
        $data = Db::table('up_article')->alias('a')
            ->join('up_article_son as','a.a_id=as.as_article_id','LEFT')
            ->join('up_u_user uu','a.a_user_id=uu.user_id','LEFT')
            ->where(function ($query) use ($shi,$start,$user_id) {
                $query->where('a_auth_type',2)->where('a_auth_city',$shi)->where('a_createtime','>=',$start)->where('as_clear_users','notlike',"%,$user_id,%");
            })
            ->whereOr(function ($query) use ($sheng,$start,$user_id) {
                $query->where('a_auth_type',3)->where('a_auth_city',$sheng)->where('a_createtime','>=',$start)->where('as_clear_users','notlike',"%,$user_id,%");
            })
            ->whereOr(function ($query) use($start,$user_id) {
                $query->where('a_auth_type',4)->where('a_createtime','>=',$start)->where('as_clear_users','notlike',"%,$user_id,%");
            })
            ->field('a_id,a_title,a_num,a_createtime,a_image,a_auth_type,user_id,user_image,user_username')
            ->order('a_createtime DESC')
            ->limit(($page-1)*10,10)
            ->select();
        foreach ($data as $k=>$v){
            if($v['a_image']){
                $images = trim($v['a_image'],',');
                $images = explode(',',$images);
                $data[$k]['a_image'] = $images[0];
            }
            //判断已读-----
            $read = Db::table('up_article_son')
                ->where('as_article_id',$v['a_id'])
                ->where('as_read_users','like',"%,$user_id,%")
                ->value('as_id');
            $data[$k]['read'] = 0;
            if($read){
                $data[$k]['read'] = 1;
            }
            //----------
        }
        return json_encode(['status'=>200,'msg'=>$data]);
    }
    /**
     * 精准消息-单条删除
     * aid  发布的消息id
     */
    public function deleteNotice(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        $users = Db::table('up_article_son')->where('as_article_id',$aid)->value('as_clear_users');
        if($users){
            $str = $users . $user_id . ',';
        }else{
            $str = ",$user_id,";
        }
        $res = Db::table('up_article_son')->where('as_article_id',$aid)->update(['as_clear_users'=>$str]);
        if($res){
            return json_encode(['status'=>200,'msg'=>'成功']);
        }else{
            return json_encode(['status'=>0,'msg'=>'失败']);
        }
    }
    /**
     * 精准消息——全部删除
     *
     */
    public function deleteNoticeAll(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        $today = date('Y-m-d H:i:s');
        $start = date("Y-m-d H:i:s",(strtotime("{$today}")-3600*24*1));
        $datas = Db::table('up_article_son')
            ->where('as_time','>',$start)
            ->where('as_clear_users','notlike',"%,$user_id,%")
            ->field('as_id,as_clear_users')
            ->select();
        if($datas){
            foreach ($datas as $k=>$v){
                $users = $v['as_clear_users'];
                if($users){
                    $str = $users . $user_id . ',';
                }else{
                    $str = ",$user_id,";
                }
                Db::table('up_article_son')->where('as_id',$v['as_id'])->update(['as_clear_users'=>$str]);
            }
        }
        return json_encode(['status'=>200,'msg'=>'success']);
    }
    /*----------------------------------------------------------------------------------*/
     /**
     * 我的消息——系统消息
     * page
     */
    public  function systemNotice()
    {
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $time2 = Db::table('up_u_user')->where('user_id',$user_id)->value('user_time');
        $data = Db::table('up_notice')
            ->where(function ($query) use ($user_id,$time2) {
                $query->where('n_user_id',$user_id)->where('n_createtime','>',$time2);
            })
            ->whereOr(function ($query) use ($user_id,$time2) {
                $query->where('n_send_type',1)->where('n_createtime','>',$time2)->where('n_clear_users','notlike',"%,$user_id,%");
            })
            ->field('n_id,n_content,n_title,n_createtime,n_send_type,n_status')
            ->order('n_createtime DESC')
            ->limit(($page-1)*10,10)
            ->select();
        foreach ($data as $k=>$v){
           $type = $v['n_send_type'];
            $data[$k]['read'] = 0;
           if($type == 2){//用户
               if($v['n_status'] == 2){//已读
                   $data[$k]['read'] = 1;
               }
           }else{
               //----判断已读-----
               $read = Db::table('up_notice')
                   ->where('n_id',$v['n_id'])
                   ->where('n_read_users','like',"%,$user_id,%")
                   ->value('n_id');
               if($read){
                   $data[$k]['read'] = 1;
               }
               //------end------
           }
        }
        return json_encode(['status'=>200,'msg'=>$data]);
    }
    /**
     * 我的消息——系统消息详情
     * nid
     */
    public  function systemNoticeInfo()
    {
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $data = Db::table('up_notice')
            ->where('n_id',$nid)
            ->field('n_id,n_content,n_title,n_createtime,n_send_type,n_status')
            ->find();
        //如果是个人的
        $type = $data['n_send_type'];
        $status = $data['n_status'];
        if($type == 2){
            if($status == 1){
                Db::table('up_notice')->where('n_id',$nid)->update(['n_status'=>2]);
            }
        }else{
            $users = Db::table('up_notice')->where('n_id',$nid)
                ->value('n_read_users');
            if($users){//你不是第一个已读的
                $users2 = Db::table('up_notice')->where('n_id',$nid)
                    ->where('n_read_users','like',"%,$user_id,%")
                    ->value('n_id');
                if(!$users2){
                    $str = $users . $user_id . ',';
                    Db::table('up_notice')->where('n_id',$nid)->update(['n_read_users'=>$str]);
                }
            }else{//你是第一个已读的
                $str = ",$user_id,";
                Db::table('up_notice')->where('n_id',$nid)->update(['n_read_users'=>$str]);
            }

        }
        return json_encode(['status'=>200,'msg'=>$data]);
    }
    /**
     * 系统消息-单条删除
     * nid  发布的消息id
     */
    public function deleteSystemNotice(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        $type = Db::table('up_notice')->where('n_id',$nid)->value('n_send_type');
        if($type == 2){
            $res = Db::table('up_notice')->where('n_id',$nid)->delete();
        }else{
            $users = Db::table('up_notice')->where('n_id',$nid)->value('n_clear_users');
            if($users){
                $str = $users . $user_id . ',';
            }else{
                $str = ",$user_id,";
            }
            $res = Db::table('up_notice')->where('n_id',$nid)->update(['n_clear_users'=>$str]);
        }

        if($res){
            return json_encode(['status'=>200,'msg'=>'成功']);
        }else{
            return json_encode(['status'=>0,'msg'=>'失败']);
        }
    }
    /**
     * 系统消息——全部删除
     *
     */
    public function deleteSystemNoticeAll()
    {
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $returnData['status'] = 301;
            $returnData['msg'] = "Token失效！请重新登录！";
            return json_encode($returnData);
        }
        $time = Db::table('up_u_user')->where('user_id',$user_id)->value('user_time');
        //先清除个人的
        Db::table('up_notice')->where('n_user_id',$user_id)->delete();
        //----------
        $datas = Db::table('up_notice')
            ->where('n_send_type',1)
            ->where('n_createtime','>',$time)
            ->where('n_clear_users','notlike',"%,$user_id,%")
            ->field('n_id,n_clear_users')
            ->select();
        if($datas){
            foreach ($datas as $k=>$v){
                $users = $v['n_clear_users'];
                if($users){
                    $str = $users . $user_id . ',';
                }else{
                    $str = ",$user_id,";
                }
                Db::table('up_notice')->where('n_id',$v['n_id'])->update(['n_clear_users'=>$str]);
            }
        }
        return json_encode(['status'=>200,'msg'=>'success']);
    }

    /**
     * getUserData 获取用户详细信息
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return string|\think\response\Json
     */
    public function getUserData(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $data = Db::table('up_u_user')
            ->alias('u')
            ->join('up_area us','us.district_id=u.user_sheng','left')
            ->join('up_area ui','ui.district_id=u.user_shi','left')
            ->join('up_area uq','uq.district_id=u.user_qu','left')
            ->where('user_id',$user_id)
            ->field('user_id,user_username,user_image,user_app_count,user_sheng,user_shi,user_qu,us.district sheng,ui.district shi,uq.district qu')
            ->find();
        $type =Db::table('up_user_auth')
            ->where(['uauth_user_id'=>$user_id,'uauth_status'=>1])
            ->whereTime('uauth_end','>=',time())
            ->field('uauth_type,uauth_start,uauth_end')
            ->select();
        if(!empty($type)){
            $flag = array_column($type,'uauth_type');
            array_multisort($flag, SORT_DESC, $type);
            $IDS = array_column ($type,'uauth_type');
            switch (max($IDS)){
                case 2:
                    $data['uauth_type'] = '铜牌';
                    break;
                case 3:
                    $data['uauth_type'] = '银牌';
                    break;
                case 4:
                    $data['uauth_type'] = '金牌';
                    break;
            }
            foreach($type as $key=>$vo){
                switch($type[$key]['uauth_type']){
                    case 2:
                        $type[$key]['uauth_type'] = '铜牌召集令';
                        break;
                    case 3:
                        $type[$key]['uauth_type'] = '银牌召集令';
                        break;
                    case 4:
                        $type[$key]['uauth_type'] = '金牌召集令';
                        break;
                }
            }
            $data['VIP'] = $type;
        }else{
            $data['uauth_type'] = "";
            $data['VIP'] = '';
        }
        $this->apiSuccess($data);
    }

    /**
     * editUserData 修改用户详细信息
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return string|\think\response\Json
     */
    public function editUserData(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $data = [
            'user_update_time'=>date('Y-m-d H:i:s'),
        ];
        if(isset($image)){
            $data['user_image'] = $image;
        }
        if(isset($username)){
            $data['user_username'] = $username;
        }
        if(isset($sheng)){
            $data['user_sheng'] = $sheng;
        }
        if(isset($shi)){
            $data['user_shi'] = $shi;
        }
        if(isset($qu)){
            $data['user_qu'] = $qu;
        }
        $res = Db::table('up_u_user')->where('user_id',$user_id)->update($data);
        if($res){
            $this->apiSuccess();
        }else{
            $this->apiError('E002');
        }
    }

    /**
     * getMyFabu 获取我发布的信息
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @param $page 页码
     * @return string|\think\response\Json
     */
    public function getMyFabu(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $data = Db::table('up_article')
            ->where(['a_user_id'=>$user_id,'a_del'=>1])
            ->field('a_id,a_title,a_createtime,a_num,a_image,a_year')
            ->order('a_createtime desc')
            ->page($page,10)
            ->select();
        foreach($data as $key=>$vo){
            $data[$key]['a_createtime'] = substr($data[$key]['a_createtime'],5,-3);
        }
        $new_arr = array();
        foreach($data as $k=>$v ){
            $new_arr[$v['a_year']][] = $v;
        }
        $big = [];
        foreach($new_arr as $key=>$vo){
            $arr['year'] = $key;
            $arr['data'] = $vo;
            $big[] = $arr;
        }
        $this->apiSuccess($big);
    }

    /**
     * delMyFabu 删除我发布的信息
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @param $aid 信息id
     * @return string|\think\response\Json
     */
    public function delMyFabu(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $res = Db::table('up_article')->where('a_id',$aid)->update(['a_del'=>2]);
        if($res){
            $this->apiSuccess();
        }else{
            $this->apiError('E001');
        }
    }

    /**
     * getMySuccessOrder 获取我购买成功的订单
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @param $page 页码
     * @return string|\think\response\Json
     */
    public function getMySuccessOrder(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $data = Db::table('up_order')
            ->alias('uo')
            ->join('up_user_auth_long al','uo.order_long_id=al.long_id','left')
            ->where(['order_user_id'=>$user_id,'order_status'=>1])
            ->field('uo.order_id,uo.order_datetime,uo.order_long_type,uo.order_money,al.long_id,uo.order_start,uo.order_end')
            ->order('uo.order_datetime desc')
            ->page($page,10)
            ->select();
        foreach($data as $key=>$vo){
            switch($data[$key]['order_long_type']){
                case 2:
                    $data[$key]['order_long_type'] = '铜牌';
                    break;
                case 3:
                    $data[$key]['order_long_type'] = '银牌';
                    break;
                case 4:
                    $data[$key]['order_long_type'] = '金牌';
                    break;
            }
            $start = strtotime($data[$key]['order_start']);
            $end = strtotime($data[$key]['order_end']);
            $t = $end - $start;
            $mon = (int) ($t / (86400 * 30));
            $data[$key]['long'] = $mon;
        }
        $this->apiSuccess($data);
    }

    /**
     * getFailedOrder 获取我购买失败的订单
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @param $page 页码
     * @return string|\think\response\Json
     */
    public function getFailedOrder(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $data = Db::table('up_order')
            ->alias('uo')
            ->join('up_user_auth_long al','uo.order_long_id=al.long_id','left')
            ->where(['order_user_id'=>$user_id,'order_status'=>2])
            ->field('uo.order_id,uo.order_datetime,uo.order_long_type,uo.order_money,al.long_how')
            ->order('uo.order_datetime desc')
            ->page($page,10)
            ->select();
        foreach($data as $key=>$vo){
            switch($data[$key]['order_long_type']){
                case 2:
                    $data[$key]['order_long_type'] = '铜牌';
                    break;
                case 3:
                    $data[$key]['order_long_type'] = '银牌';
                    break;
                case 4:
                    $data[$key]['order_long_type'] = '金牌';
                    break;
            }
        }
        $this->apiSuccess($data);
    }

    /**
     * attestation 商家认证
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return string|\think\response\Json
     */
    public function attestation(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        if($relname=="" || $attphone == "" || $attadd ==""){
            $this->apiError(110);
        }
        $time = date('Y-m-d H:i:s');
        $data = [
            'user_rel_name'=>$relname,
            'user_att_phone'=>$attphone,
            'user_att_add'=>$attadd,
            'user_attestation'=>4,
            'user_update_time'=>$time
        ];
        if($identity == "" && $side =="" && $business == ""){
            return json(['code'=>100,'msg'=>'请上传手持身份证照或营业执照']);
        }else{
            $data['user_identity_image'] = $identity;
            $data['user_identity_side'] = $side;
            $data['user_business_image'] = $business;
        }
        $param = [
            'n_title'=>'认证信息审核中',
            'n_content'=>'您提交的商家认证信息正在审核中，请耐心等待',
            'n_createtime'=>$time,
            'n_type'=>5,
            'n_send_type'=>2,
            'n_user_id'=>$user_id,
            'n_read_users'=>',0,',
            'n_clear_users'=>',0,',
            'n_status'=>1
        ];
        // 启动事务
        Db::startTrans();
        try{
            Db::table('up_u_user')->where('user_id',$user_id)->update($data);
            Db::table('up_notice')->insert($param);
            // 提交事务
            Db::commit();
            $this->Jpush("$user_id", "认证信息审核中", 1, ['type'=>1]);
            $this->apiSuccess();
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
            $this->apiError('K100');
        }
    }

    /**
     * attestationFailure 查看商家认证
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return string|\think\response\Json
     */
    public function attestationFailure(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $data = Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->field('user_attestation,user_id,user_rel_name,user_att_phone,user_att_add,user_identity_image,user_business_image,user_identity_side')
            ->find();
        $this->apiSuccess($data);
    }

    /**
     * feedBack 意见反馈
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return string|\think\response\Json
     */
    public function feedBack(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        if($content=="" && $image == ""){
            $this->apiError(110);
        }
        $data = [
            'feedback_user_id'=>$user_id,
            'feedback_content'=>$content,
            'feedback_time' =>date('Y-m-d H:i:s'),
            'feedback_image'=>$image
        ];
        $res = Db::table('up_feedback')->insert($data);
        if($res){
            $this->apiSuccess();
        }else{
            $this->apiError('K100');
        }
    }
    /**
     * getAboutUs 关于我们
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return string|\think\response\Json
     */
    public function getAboutUs(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $data  = Db::table('up_about_us')->find();
        $this->apiSuccess($data);
    }


    /**
     * buyAuth 精准发布
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @param $type 2铜牌  3银牌  4金牌
     * @param $phone_type 1:苹果 2:安卓
     * @return string|\think\response\Json
     */
    public function buyAuth(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $data = Db::table('up_user_auth_long')
            ->where(['long_type'=>$type,'long_phone'=>$phone_type])
            ->field('long_id,long_type,long_how,long_money')
            ->order('long_how asc')
            ->select();

        $type = Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->value('user_attestation');
        return json(['status'=>200,'msg'=>'成功','data'=>$data,'type'=>$type]);
    }

    /**
     * province 省
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function province(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $province = Db::table('up_area')
            ->where('pid',1)
            ->field('district_id,district')
            ->order('district_id asc')
            ->select();
        $this->apiSuccess($province);
    }

    /**
     * place 地区三级联动
     * @return \think\response\Json
     */
    public function area(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $area = Db::name('area')
            ->where('pid',$id)
            ->field('district_id,district')
            ->order('district_id asc')
            ->select();
        $this->apiSuccess($area);
    }

    /**
     * location 自动定位返回id
     * $location  地区名称
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return 返回数组
     */
    public function location (){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        if(isset($sheng)){
            $shengID = Db::table('up_area')
                ->where('district',$sheng)
                ->value('district_id');
            $res['sheng'] = $shengID;
        }
        if(isset($shi)){
            $shiID = Db::table('up_area')
                ->where('district',$shi)
                ->value('district_id');
            $res['shi'] = $shiID;
        }
        if(isset($qu)){
            $quID = Db::table('up_area')
                ->where('district',$qu)
                ->value('district_id');
            $res['qu'] = $quID;
        }
        $this->apiSuccess($res);
    }

    /**
     * 客服邮箱
     * @param $user_id 用户id
     * @param $time 时间
     * @param $value 加密值
     * @return 返回数组
     */
    public function email(){
        extract(input());
        $auth = $this->checkAll($user_id,$time,$value,$reqKey);
        if($auth == false){
            $this->apiError(301);
        }
        $email = Db::table('up_about_us')->value('a_service_email');
        $this->apiSuccess($email);
    }

    /**
     * 注册协议
     * @return 返回数组
     */
    public function getAgreement(){
        $agreement = Db::table('up_about_us')->value('a_register_agreement');
        $this->apiSuccess($agreement);
    }
}